#include "../include/sdf.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int SDF_OpenDevice(void **phDeviceHandle)
{
    FILE *fd;
    fd = fopen("file.txt", "r");
    if(fd != NULL){
        *phDeviceHandle = (void *)fd;
        printf("Open device successfully.\n");
        return SDR_OK;
    }
    return SDR_OPENDEVICE;
}

int SDF_CloseDevice(void *hDeviceHandle)
{
    hDeviceHandle = NULL;
    printf("Close device successfully.\n");
    return SDR_OK;
}

int SDF_OpenSession(void *hDeviceHandle, void **phSessionHandle)
{
    *phSessionHandle = hDeviceHandle;
    if (*phSessionHandle != NULL){
        printf("Open session successfully.\n");
        return SDR_OK;
    }
    return SDR_OPENSESSION;
}

int SDF_CloseSession(void *hSessionHandle)
{
    hSessionHandle = NULL;
    printf("Close session successfully.\n");
    return SDR_OK;
}

int SDF_GetDeviceInfo(void *hSessionHandle, DEVICEINFO *pstDeviceInfo)
{
    if(hSessionHandle != NULL){
        strcpy((*pstDeviceInfo).IssuerName, "20181311gyc");
        strcpy((*pstDeviceInfo).DeviceName, "DEVICE");
        strcpy((*pstDeviceInfo).DeviceSerial, "0000000000000001");
        (*pstDeviceInfo).DeviceVersion = 1;
        (*pstDeviceInfo).StandardVersion = 1;
        (*pstDeviceInfo).AsymAlgAbility[0] = 0;
        (*pstDeviceInfo).AsymAlgAbility[1] = 0;
        (*pstDeviceInfo).SymAlgAbility = 1;
        (*pstDeviceInfo).HashAlgAbility = 1;
        (*pstDeviceInfo).BufferSize = 128;
        printf("Get deviceinfo successfully.\n");
        return SDR_OK;
    }
    return SDR_COMMFAIL;
}

int SDF_GenerateRandom(void *hSessionHandle, unsigned int uiLength, unsigned char *pucRandom)
{
    return SDR_OK;
}

int SDF_ExportSignPublicKey_ECC(void *hSessionHandle, unsigned int uiKeyIndex, ECCrefPublicKey *pucPublicKey)
{
    return SDR_OK;
}

int SDF_ExportEncPublicKey_ECC(void *hSessionHandle, unsigned int uiKeyIndex, ECCrefPublicKey *pucPublicKey)
{
    return SDR_OK;
}

int SDF_GenerateKeyPair_ECC(void *hSessionHandle, unsigned int uiAlgID, unsigned int uiKeyBits, ECCrefPublicKey *pucPublicKey, ECCrefPrivateKey *pucPrivateKey)
{
    return SDR_OK;
}

int SDF_ExternalVerify_ECC(void *hSessionHandle, unsigned int uiAlgID, ECCrefPublicKey *pucPublicKey, unsigned char *pucDataInput, unsigned int uiInputLength, ECCSignature *pucSignature)
{
    return SDR_OK;
}

int SDF_InternalSign_ECC(void *hSessionHandle, unsigned int uiISKIndex, unsigned char *pucData, unsigned int uiDataLength, ECCSignature *pucSignature)
{
    return SDR_OK;
}

int SDF_ExternalEncrypt_ECC(void *hSessionHandle, unsigned int uiAlgID, ECCrefPublicKey *pucPublicKey, unsigned int uiDataLength, ECCCipher *pucEncData)
{
    return SDR_OK;
}

int SDF_Encrypt(void *hSessionHandle, void *hKeyHandle, unsigned int uiAlgID, unsigned char *pucIV, unsigned char *pucData, unsigned int uiDataLength, unsigned char *pucEncData, unsigned int *puiEncDataLength)
{
    return SDR_OK;
}

int SDF_Decrypt(void *hSessionHandle, void *hKeyHandle, unsigned int uiAlgID, unsigned char *pucIV, unsigned char *pucEncData, unsigned int uiEncDataLength, unsigned char *pucData, unsigned int *puiDataLength)
{
    return SDR_OK;
}

int CalculateMAC(void *hSessionHandle, void *hKeyHandle, unsigned int uiAlgID, unsigned char *pucIV, unsigned char *pucData, unsigned int uiDataLength, unsigned char *pucMAC, unsigned int *puiMACLength)
{
    return SDR_OK;
}

int SDF_HashInit(void *hSessionHandle, unsigned int uiAlgID, ECCrefPublicKey *pucPublicKey, unsigned char *pucID, unsigned int uiDLength)
{
    return SDR_OK;
}

int SDF_HashUpdate(void *hSession, unsigned char *pucData, unsigned int uiDataLength)
{
    return SDR_OK;
}

int SDF_HashFinal(void *hSessionHandle, unsigned char *pucHash, unsigned int *puiHashLength)
{
    return SDR_OK;
}